package com.atguigu.gulimall.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.atguigu.gulimall.ware.vo.MergeVo;
import com.atguigu.gulimall.ware.vo.PurchaseDoneVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atguigu.gulimall.ware.entity.PurchaseEntity;
import com.atguigu.gulimall.ware.service.PurchaseService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;


/**
 * 采购信息
 *
 * @author GCQ
 * @Todo
 * @email python0526@163.com
 * @date 2020-12-18 14:36:45
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
    * @需求描述: 系统管理员-库存采购单组 模块 采购成功 完成采购需求
    * @创建人: 郭承乾
    * @创建时间: 2020/12/23 17:01
    * @修改需求:
    * @修改人:
    * @修改时间:
    * @需求思路:
    */
    @RequestMapping("/done")
    public R list(@RequestBody PurchaseDoneVo doneVo) {
        purchaseService.done(doneVo);

        return R.ok();
    }


    /**
     * @需求描述: 系统管理员-库存采购单组 模块 查询未领取的采购单
     * @创建人: 郭承乾
     * @创建时间: 2020/12/23 14:58
     * @修改需求:
     * @修改人:
     * @修改时间:
     * @需求思路:
     */
    @RequestMapping("/unreceive/list")
    public R unreceivelise(@RequestParam Map<String, Object> params) {
        PageUtils page = purchaseService.queryPageUnreceivePurchase(params);

        return R.ok().put("page", page);
    }

    /**
    * @需求描述: 系统管理员-库存采购单组 模块 合并采购单
    * @创建人: 郭承乾
    * @创建时间: 2020/12/23 15:13
    * @修改需求:
    * @修改人:
    * @修改时间:
    * @需求思路:
    */
    @PostMapping("/merge")
    public R merge(@RequestBody MergeVo mergeVo) {
        purchaseService.merge(mergeVo);
        return R.ok();
    }

    /**
     * @需求描述: 系统管理员-库存采购单组 模块 用户在APP上领取采购单进行采购
     * @创建人: 郭承乾
     * @创建时间: 2020/12/23 15:13
     * @修改需求:
     * @修改人:
     * @修改时间:
     * @需求思路:
     */
    @PostMapping("/received")
    public R received(@RequestBody List<Long> ids) {
        purchaseService.received(ids);
        return R.ok();
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        PurchaseEntity purchase = purchaseService.getById(id);

        return R.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PurchaseEntity purchase) {
        purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PurchaseEntity purchase) {
        purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
